<template>
  <div>
    <CityHeader></CityHeader>
    <CitySearch :cities="cities"></CitySearch>
    <CityList :city="city" :hotCities="hotCities" :cities="cities" :letter="letter"></CityList>
    <CityAlphabet 
    :cities="cities"
    @change="handleLetterChange"
    >
    </CityAlphabet>
  </div>
</template>

<script>
import CityHeader from "./components/Header";
import CitySearch from "./components/Search";
import CityList from "./components/List";
import CityAlphabet from "./components/Alphabet";
import axios from "axios";
export default {
  name: "City",
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data() {
    return {
      city:'',
      cities: {},
      hotCities: [],
      letter:'',
    };
  },
  methods: {
    getCityInfo() {
      axios
        .get("http://localhost:8080/api/CityImg")
        .then(res => {
          res = res.data;
          if (res.ret && res.datas) {
            this.city = res.datas.city
            this.cities = res.datas.cities;
            this.hotCities = res.datas.hotCities
          }
        })
        .catch(err => {
          console.log("请求失败");
        });
      axios
        .get("http://192.168.0.104:8080/api/CityImg")
        .then(res => {
          res = res.data;
          if (res.ret && res.datas) {
            this.city = res.datas.city
            this.cities = res.datas.cities;
            this.hotCities = res.datas.hotCities
          }
        })
        .catch(err => {
          console.log("请求失败");
        });
    },
    // 给CityAlphabet绑定一个自定义事件
    // CityAlphabet调用自定义事件并传参
    // 这边接收参数
    handleLetterChange(letter){
      // 将参数传给CityList
      this.letter = letter;
    }
  },
  mounted() {
    this.getCityInfo();
  }
};
</script>

<style lang="less" scoped>

</style>
